%% copy riak-0.14.2 source to learn dynamo implementation and erlang
%% author: lichuang
-module(edynamo_app).

-behaviour(application).

%% Application callbacks
-export([start/2, stop/1]).

%% ===================================================================
%% Application callbacks
%% ===================================================================
start(_StartType, _StartArgs) ->
  case edynamo_sup:start_link() of
    {ok, Pid} ->
      ok = edynamo_ring_events:add_handler(edynamo_ring_handler, []),
      %% Append defaults for riak_kv buckets to the bucket defaults
      %% TODO: Need to revisit this. Buckets are typically created
      %% by a specific entity; seems lame to append a bunch of unused
      %% metadata to buckets that may not be appropriate for the bucket.
      edynamo_bucket:append_bucket_defaults(
        [{linkfun, {modfun, riak_kv_wm_link_walker, mapreduce_linkfun}},
          {old_vclock, 86400},
          {young_vclock, 20},
          {big_vclock, 50},
          {small_vclock, 10},
          {r, quorum},
          {w, quorum},
          {dw, quorum},
          {rw, quorum}]),
      %% Go ahead and mark the riak_kv service as up in the node watcher.
      %% The riak_core_ring_handler blocks until all vnodes have been started
      %% synchronously.
      edynamo_core:register_vnode_module(edynamo_kv_vnode),
      edynamo_node_watcher:service_up(edynamo, self()),
      {ok, Pid};
    {error, Reason} ->
      {error, Reason}
  end.

stop(_State) ->
  ok.
